USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Insert]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Insert record into table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Stores_Products](/*[ID], [Store_ID], [Product_ID], [Product_Quantity], [Product_Price], [MeasureUnit_ID], [SafetyLimit]*/)
	VALUES     (/*@ID, @Store_ID, @Product_ID, @Product_Quantity, @Product_Price, @MeasureUnit_ID, @SafetyLimit*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
    WHERE  ( [ID] =@ID )
	AND  ( [Store_ID] =@Store_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Product_Quantity] =@Product_Quantity )
	AND  ( [Product_Price] =@Product_Price )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [SafetyLimit] =@SafetyLimit )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-update]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Update record in table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Stores_Products] SET 
		/*[ID] =@ID, 
		[Store_ID] =@Store_ID, 
		[Product_ID] =@Product_ID, 
		[Product_Quantity] =@Product_Quantity, 
		[Product_Price] =@Product_Price, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[SafetyLimit] =@SafetyLimit*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Insert-Update]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Insert OR Update record into table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Stores_Products] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Stores_Products](/*[ID], [Store_ID], [Product_ID], [Product_Quantity], [Product_Price], [MeasureUnit_ID], [SafetyLimit]*/)
		VALUES     (/*@ID, @Store_ID, @Product_ID, @Product_Quantity, @Product_Price, @MeasureUnit_ID, @SafetyLimit*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Stores_Products] SET 
			/*[ID] =@ID, 
			[Store_ID] =@Store_ID, 
			[Product_ID] =@Product_ID, 
			[Product_Quantity] =@Product_Quantity, 
			[Product_Price] =@Product_Price, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[SafetyLimit] =@SafetyLimit*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Delete]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	delete records from table [dbo].[Stores_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Quantity float =null  , 
	@Product_Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@SafetyLimit float =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Stores_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Quantity] = ISNULL(@Product_Quantity, [Product_Quantity]) )
	AND ( [Product_Price] = ISNULL(@Product_Price, [Product_Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [SafetyLimit] = ISNULL(@SafetyLimit, [SafetyLimit]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Select]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	select records from table [dbo].[Stores_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Quantity float =null  , 
	@Product_Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@SafetyLimit float =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Stores_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Quantity] = ISNULL(@Product_Quantity, [Product_Quantity]) )
	AND ( [Product_Price] = ISNULL(@Product_Price, [Product_Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [SafetyLimit] = ISNULL(@SafetyLimit, [SafetyLimit]) )*/
END
GO
-- =============================================
